package com.zyx.beancopy.copier.util;

import com.google.common.base.CaseFormat;

/**
 * @author Yaxi.Zhang
 * @since 2022/4/21 10:19
 */
public class StrUtil {
    private static final char UNDER_LINE = '_';

    /** 下划线转驼峰 */
    public static String toCamelCase(String name) {
        if (null == name || name.length() == 0) {
            return null;
        }

        if (!contains(name, UNDER_LINE)) {
            return name;
        }

        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
    }

    /** 驼峰转下划线 */
    public static String toUnderCase(String name) {
        if (name == null) {
            return name;
        }
        return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
    }

    public static boolean contains(String str, char searchChar) {
        return str.indexOf(searchChar) >= 0;
    }


    public static void main(String[] args) {
        String name = "userName";
        System.out.println(toCamelCase(name) + "|" + toUnderCase(name));
        name = "user_nName_User";
        System.out.println(toCamelCase(name) + "|" + toUnderCase(name));
    }
}